package com.itheima.crm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itheima.common.utils.Page;
import com.itheima.crm.dao.CustomerMapper;
import com.itheima.crm.pojo.Customer;
import com.itheima.crm.pojo.QueryVo;

@Service
public class CustomerServiceImpl implements CustomerService {

	@Autowired
	private CustomerMapper customerMapper;

	@Override
	public Page<Customer> queryCustomerByQueryVo(QueryVo queryVo) {
		// 设置查询条件,从哪一条数据开始查
		queryVo.setStart((queryVo.getPage() - 1) * queryVo.getRows());

		// 查询数据结果集
		List<Customer> list = customerMapper.queryCustomerByQueryVo(queryVo);
		// 查询到的数据总条数
		int total = customerMapper.queryCountByQueryVo(queryVo);
		
		Page<Customer> page = new Page<>();
		page.setTotal(total);
		page.setPage(queryVo.getPage());
		page.setRows(list);
		page.setSize(queryVo.getRows());
		
		return page;
	}

	@Override
	public Customer queryCustomerById(Long id) {
		return customerMapper.queryCustomerById(id);
	}

	@Override
	public void updateCustomerById(Customer customer) {
		customerMapper.updateCustomerById(customer);
	}
	
	@Override
	public void deleteCustomerById(Long id) {
		customerMapper.deleteCustomerById(id);
	}

}
